<template>
  <div id="ntko"></div>
</template>

<script>
export default {
  name: "Ntko",

  mounted() {
    //alert(this.browser);

    this.$nextTick(() => {
      // 请勿修改，否则可能出错
      var userAgent = navigator.userAgent,
        rMsie = /(msie\s|trident.*rv:)([\w.]+)/,
        rFirefox = /(firefox)\/([\w.]+)/,
        rOpera = /(opera).+version\/([\w.]+)/,
        rChrome = /(chrome)\/([\w.]+)/,
        rSafari = /version\/([\w.]+).*(safari)/;
      var browser;
      var version;
      var ua = userAgent.toLowerCase();
      function uaMatch(ua) {
        var match = rMsie.exec(ua);
        if (match != null) {
          return { browser: "IE", version: match[2] || "0" };
        }
        var match = rFirefox.exec(ua);
        if (match != null) {
          return { browser: match[1] || "", version: match[2] || "0" };
        }
        var match = rOpera.exec(ua);
        if (match != null) {
          return { browser: match[1] || "", version: match[2] || "0" };
        }
        var match = rChrome.exec(ua);
        if (match != null) {
          return { browser: match[1] || "", version: match[2] || "0" };
        }
        var match = rSafari.exec(ua);
        if (match != null) {
          return { browser: match[2] || "", version: match[1] || "0" };
        }
        if (match != null) {
          return { browser: "", version: "0" };
        }
      }
      var browserMatch = uaMatch(userAgent.toLowerCase());
      if (browserMatch.browser) {
        browser = browserMatch.browser;
        version = browserMatch.version;
      }
      //document.write(browser);
      /*
谷歌浏览器事件接管
*/
      function OnComplete2(type, code, html) {
        //alert(type);
        //alert(code);
      }
      function OnComplete(type, code, html) {
        //alert(type);
        //alert(code);
      }
      function OnComplete3(str, doc) {
        TANGER_OCX_OBJ.activeDocument.saved = true; //saved属性用来判断文档是否被修改过,文档打开的时候设置成ture,当文档被修改,自动被设置为false,该属性由office提供.
        //	TANGER_OCX_OBJ.SetReadOnly(true,"");
        //TANGER_OCX_OBJ.ActiveDocument.Protect(1,true,"123");
        //获取文档控件中打开的文档的文档类型
        switch (TANGER_OCX_OBJ.doctype) {
          case 1:
            fileType = "Word.Document";
            fileTypeSimple = "wrod";
            break;
          case 2:
            fileType = "Excel.Sheet";
            fileTypeSimple = "excel";
            break;
          case 3:
            fileType = "PowerPoint.Show";
            fileTypeSimple = "ppt";
            break;
          case 4:
            fileType = "Visio.Drawing";
            break;
          case 5:
            fileType = "MSProject.Project";
            break;
          case 6:
            fileType = "WPS Doc";
            fileTypeSimple = "wps";
            break;
          case 7:
            fileType = "Kingsoft Sheet";
            fileTypeSimple = "et";
            break;
          default:
            fileType = "unkownfiletype";
            fileTypeSimple = "unkownfiletype";
        }

        //alert("ondocumentopened成功回调");
      }
      function publishashtml(type, code, html) {}
      function publishaspdf(type, code, html) {}
      function saveasotherurl(type, code, html) {}
      function dowebget(type, code, html) {}
      function webExecute(type, code, html) {}
      function webExecute2(type, code, html) {}
      function FileCommand(TANGER_OCX_str, TANGER_OCX_obj) {
        if (TANGER_OCX_str == 3) {
          TANGER_OCX_OBJ.CancelLastCommand = true;
        }
      }
      function CustomMenuCmd(
        menuPos,
        submenuPos,
        subsubmenuPos,
        menuCaption,
        menuID
      ) {
        //alert("第" + menuPos +","+ submenuPos +","+ subsubmenuPos +"个菜单项,menuID="+menuID+",菜单标题为\""+menuCaption+"\"的命令被执行.");
      }
      var classidx64 = "A64E3073-2016-4baf-A89D-FFE1FAA10EE0";

      var classid = "A64E3073-2016-4baf-A89D-FFE1FAA10EC0";
      var codebase = "officecontrol/OfficeControl.cab#version=5,0,3,9";
      var codebase64 = "officecontrol/OfficeControlx64.cab#version=5,0,3,9";
      if (browser == "IE") {
        //alert(window.navigator.platform);
        if (window.navigator.platform == "Win32") {
          
             let domStr = "";
          domStr +="<!-- 用来产生编辑状态的ActiveX控件的JS脚本-->   "
         domStr +=
            "<!-- 因为微软的ActiveX新机制，需要一个外部引入的js-->   "
          domStr +=
            '<object id="TANGER_OCX" classid="clsid:' + classid + '"'
         
          domStr +=
            'codebase="' + codebase + '" width="100%" height="100%">   '
        
          domStr +='<param name="IsUseUTF8URL" value="-1">   '
          domStr +='<param name="IsUseUTF8Data" value="-1">   '
         domStr +='<param name="BorderStyle" value="1">   '
          domStr +='<param name="BorderColor" value="14402205">   '
          domStr +='<param name="TitlebarColor" value="15658734">   '

           domStr +=
            '<param name="ProductCaption" value="国务院国有资产监督管理委员会"> '
         
          domStr +=
            '<param name="ProductKey" value="4FF2EC7F86730918AA3F9838F898D1F9D6C3EB32">'
        
          domStr +=
            '<param name="NoExpireKey" value="58E43B4F862E02C3E3FF7FF8FD0AB52D">'
          

          domStr +='<param name="TitlebarTextColor" value="0">   '
           domStr +='<param name="MenubarColor" value="14402205">   '
           domStr +='<param name="MenuButtonColor" VALUE="16180947">   '
           domStr +='<param name="MenuBarStyle" value="3">   '
           domStr +='<param name="MenuButtonStyle" value="7">   '
          domStr +='<param name="WebUserName" value="NTKO">   '
          domStr +=
            '<param name="Caption" value="NTKO OFFICE文档控件示例演示 http://www.ntko.com">   '
        
          domStr +=
            '<SPAN STYLE="color:red">不能装载文档控件。请在检查浏览器的选项中检查浏览器的安全设置。</SPAN>   '
         
          domStr += "</object>"
             document.getElementById("ntko").innerHTML += domStr;
        }
        if (window.navigator.platform == "Win64") {
           let domStr = "";
         domStr +="<!-- 用来产生编辑状态的ActiveX控件的JS脚本-->   "
          domStr +=
            "<!-- 因为微软的ActiveX新机制，需要一个外部引入的js-->   "
          
          domStr +=
            '<object id="TANGER_OCX" classid="clsid:' + classidx64 + '"'
         
        domStr +=
            'codebase="' + codebase64 + '" width="100%" height="100%">   '
       
          domStr +='<param name="IsUseUTF8URL" value="-1">   '
          domStr +='<param name="IsUseUTF8Data" value="-1">   '
          domStr +='<param name="BorderStyle" value="1">   '
          domStr +='<param name="BorderColor" value="14402205">   '
          domStr +='<param name="TitlebarColor" value="15658734">   '
          domStr +='<param name="isoptforopenspeed" value="0">   '
          domStr +='<param name="TitlebarTextColor" value="0">   '

       domStr +=
            '<param name="ProductCaption" value="国务院国有资产监督管理委员会"> '
        
         domStr +=
            '<param name="ProductKey" value="4FF2EC7F86730918AA3F9838F898D1F9D6C3EB32">'
      
        domStr +=
            '<param name="NoExpireKey" value="58E43B4F862E02C3E3FF7FF8FD0AB52D">'
        
         domStr +='<param name="MenubarColor" value="14402205">   '
         domStr +='<param name="MenuButtonColor" VALUE="16180947">   '
          domStr +='<param name="MenuBarStyle" value="3">   '
          domStr +='<param name="MenuButtonStyle" value="7">   '
          domStr +='<param name="WebUserName" value="NTKO">   '
        domStr +=
            '<param name="Caption" value="NTKO OFFICE文档控件示例演示 http://www.ntko.com">   '
      
         domStr +=
            '<SPAN STYLE="color:red">不能装载文档控件。请在检查浏览器的选项中检查浏览器的安全设置。</SPAN>   '
         
          domStr += "</object>"
            document.getElementById("ntko").innerHTML += domStr;
        }
      } else if (browser == "firefox") {
          let domStr = "";
        domStr +=
          '<object id="TANGER_OCX" type="application/ntko-plug"  codebase="' +
            codebase +
            '" width="100%" height="100%" ForOnSaveToURL="OnComplete2" ForOnBeginOpenFromURL="OnComplete" ForOndocumentopened="OnComplete3"'
       

        domStr +='ForOnpublishAshtmltourl="publishashtml"'
       domStr +='ForOnpublishAspdftourl="publishaspdf"'
        domStr +='ForOnSaveAsOtherFormatToUrl="saveasotherurl"'
        domStr +='ForOnDoWebGet="dowebget"'
        domStr +='ForOnDoWebExecute="webExecute"'
        domStr +='ForOnDoWebExecute2="webExecute2"'
        domStr +='ForOnFileCommand="FileCommand"'
        domStr +='ForOnCustomMenuCmd2="CustomMenuCmd"'
       domStr +='_IsUseUTF8URL="-1"   '

       domStr +='_ProductCaption="国务院国有资产监督管理委员会" '
       domStr +=
          '_ProductKey="4FF2EC7F86730918AA3F9838F898D1F9D6C3EB32" '
        
        domStr +='_NoExpireKey="58E43B4F862E02C3E3FF7FF8FD0AB52D" '

       domStr +='_IsUseUTF8Data="-1"   '
        domStr +='_BorderStyle="1"   '
        domStr +='_BorderColor="14402205"   '
        domStr +='_MenubarColor="14402205"   '
        domStr +='_MenuButtonColor="16180947"   '
       domStr +='_MenuBarStyle="3"  '
       domStr +='_MenuButtonStyle="7"   '
        domStr +='_WebUserName="NTKO"   '
        domStr +='clsid="{' + classid + '}" >'
        domStr +=
          '<SPAN STYLE="color:red">尚未安装NTKO Web FireFox跨浏览器插件。请点击<a href="ntkoplugins.xpi">安装组1件</a></SPAN>   '
        
        domStr += "</object>   "
       document.getElementById("ntko").innerHTML += domStr;
      } else if (browser == "chrome") {
         let domStr = "";
         domStr += 
          '<object id="TANGER_OCX" clsid="{' +
            classid +
            '}"  ForOnSaveToURL="OnComplete2" ForOnBeginOpenFromURL="OnComplete" ForOndocumentopened="OnComplete3"'
      
        domStr += 'ForOnpublishAshtmltourl="publishashtml"'
         domStr += 'ForOnpublishAspdftourl="publishaspdf"'
         domStr += 'ForOnSaveAsOtherFormatToUrl="saveasotherurl"'
         domStr += 'ForOnDoWebGet="dowebget"'
         domStr += 'ForOnDoWebExecute="webExecute"'
         domStr += 'ForOnDoWebExecute2="webExecute2"'
        domStr += 'ForOnFileCommand="FileCommand"'

        domStr += '_ProductCaption="国务院国有资产监督管理委员会" '
      domStr += 
          '_ProductKey="4FF2EC7F86730918AA3F9838F898D1F9D6C3EB32" '
       
         domStr += '_NoExpireKey="58E43B4F862E02C3E3FF7FF8FD0AB52D" '

     domStr += 'ForOnCustomMenuCmd2="CustomMenuCmd"'
         domStr += 
          'codebase="' +
            codebase +
            '" width="100%" height="100%" type="application/ntko-plug" '
        
         domStr += '_IsUseUTF8URL="-1"   '
         domStr += '_IsUseUTF8Data="-1"   '
        domStr += '_BorderStyle="1"   '
         domStr += '_BorderColor="14402205"   '
        domStr += '_MenubarColor="14402205"   '
        domStr += '_MenuButtonColor="16180947"   '
         domStr += '_MenuBarStyle="3"  '
         domStr += '_MenuButtonStyle="7"   '
         domStr += '_WebUserName="NTKO"   '
        domStr += 
          '_Caption="NTKO OFFICE文档控件示例演示 http://www.ntko.com">    '
       
       domStr += 
          '<SPAN STYLE="color:red">尚未安装NTKO Web Chrome跨浏览器插件。请点击<a href="ntkoplugins.crx">安装组件</a></SPAN>   '
   
        domStr += "</object>"
           document.getElementById("ntko").innerHTML += domStr;
      } else if (Sys.opera) {
        alert("sorry,ntko web印章暂时不支持opera!");
      } else if (Sys.safari) {
        alert("sorry,ntko web印章暂时不支持safari!");
      }
    });
  },
};
</script>

<style>
/*全局覆盖样式，注意在其他地方不要定义ntko-demo这个样式*/

/*.ntko-demo .el-dialog__body{*/

/*padding: 0 0 0 0 !important;*/

/*}*/
</style>
